package com.gigi.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.gigi.model.BlogDO;
import com.gigi.model.IdRequest;
import com.gigi.model.ListBlogRequest;
import com.gigi.service.manual.BlogManageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 博客管理
 */
@RestController
@RequestMapping("blog-manage")
public class BlogManageController {

    private final BlogManageService blogManageService;

    public BlogManageController(BlogManageService blogManageService) {
        this.blogManageService = blogManageService;
    }

    @ApiOperation(value = "保存")
    @PostMapping("/save")
    public Response save(@RequestBody @Valid BlogDO request) {
        return blogManageService.save(request);
    }

    @ApiOperation(value = "作品列表&搜索")
    @PostMapping("/list")
    public MultiResponse<BlogDO> list(@RequestBody ListBlogRequest request) {
        return blogManageService.list(request);
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public Response delete(@RequestBody @Valid IdRequest request) {
        return blogManageService.delete(request.getId());
    }

    @ApiOperation(value = "详情")
    @PostMapping("/detail")
    public SingleResponse<BlogDO> detail(@RequestBody @Valid IdRequest request) {
        return blogManageService.detail(request.getId());
    }

    @ApiOperation(value = "热榜")
    @PostMapping("/hot")
    public MultiResponse<BlogDO> hot5() {
        return blogManageService.hot5();
    }

    @ApiOperation(value = "推荐")
    @PostMapping("/recommend")
    public MultiResponse<BlogDO> recommend(@RequestBody ListBlogRequest request) {
        return blogManageService.recommend(request);
    }

}
